define(["webgl-utils"], function(webglUtil) {
	
	var webgl = {	
		//Initialize webgl, return null if succeed
		init: function(canvas, fullscreen) {
			//Set canvas to fullscreen
			if(_fullscreen = fullscreen) {
				canvas.width 		= $(document).width();
				canvas.height 		= $(document).height();
			}
			
			//Initialize
			this.gl 			= webglUtil.setupWebGL(canvas);
			this.viewportWidth 	= canvas.width;
			this.viewportHeight	= canvas.height;
			
			//common settings
			this.gl.viewport(0,0,webgl.viewportWidth,webgl.viewportHeight);
			this.gl.clearColor(0,0,0,1);
			this.gl.enable(this.gl.DEPTH_TEST);	
			this.gl.enable(this.gl.BLEND);	
			this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE_MINUS_SRC_ALPHA);			
			
			return this.gl;
		},
		
		//Helper function to create buffer
		//ex: createStaticBuf(webgl.gl.ARRAY_BUFFER, Float32Array, [0,0,0, 0,1,0, 1,1,0], 3)
		createStaticBuf: function(bufType, dataType, data, itemSize) {
			var gl	= this.gl;
			var buf = gl.createBuffer();
			gl.bindBuffer(bufType, buf);
			gl.bufferData(bufType, new dataType(data), gl.STATIC_DRAW);
			buf.itemSize = itemSize;
			buf.numItems = data.length / itemSize;
			return buf;
		},
		
		//Helper function to point attribute arr
		//loc: get it from shader's attribute
		//buf: buffer created from createStaticBuf()
		pointAttrib: function(loc, buf) {
			var gl = this.gl;
			gl.bindBuffer(gl.ARRAY_BUFFER, buf);
			gl.vertexAttribPointer(loc, buf.itemSize, gl.FLOAT, false, 0, 0);
		}
	};
	
	return webgl;
	
	/*
	var canvas			= $('canvas')[0];
	var gl 				= canvas.getContext("experimental-webgl");
	gl.viewportWidth 	= canvas.width;
	gl.viewportHeight	= canvas.height;
	
	return gl;
	*/
});